<template>
	<view class="wrap">

		<!-- <monitorScanCode v-if="scanCodeIsShow"></monitorScanCode> -->
		<!-- <u-swiper :height="270" :list="imgList" :title="false" @click="imgListClick"></u-swiper> -->
		<!-- <view class="">
				<u-input v-model="value" :type="type" :border="border" @click="show = true" />
				<u-action-sheet :list="actionSheetList" v-model="show" @click="actionSheetCallback"></u-action-sheet>
			</view> -->
		<!-- <view>
			    <sk-container>
			      <sk-menu></sk-menu>
			    </sk-container>
			  </view> -->
		<view v-show="!baseService">
			<uni-card>
				<h3>{{errText}}</h3>
			</uni-card>


		</view>
		<view v-show="baseService">
			<!-- 已完成注册,保存 -->
			<u-form :model="form" class="apply-form-field example-body">
				<!-- <u-gap height="20" bg-color="#f5f5f5"></u-gap> -->
				<u-form-item label="分仓选择" label-width="150" right-icon="arrow-right">
					<u-input placeholder="请选择" v-model="value" type="select" @click="show = true"
						class="form-field-select" />
					<u-action-sheet border-radius='20' :list="actionSheetList" v-model="show"
						@click="actionSheetCallback"></u-action-sheet>
				</u-form-item>

			</u-form>
			<!-- <u-gap height="20" bg-color="#f5f5f5"></u-gap> -->
			<!-- <view v-if="value.includes('上海宠物') || value.includes('测试')"> -->
				<!-- (上海宠物) -->
				<view class="workbench-title">基础应用(福贝)</view>
				<view class="toolbar">
					<u-grid class="grid" :col="4" :border="false">
						<u-grid-item :index="0" @click="navTo('/pages/shanghai-chongwu/storage/index')">
							<view class="home-icon icon-color01">
								<i class="iconfont icon-a-shangjiadan3x"></i>
							</view>
							<view class="grid-text">电商入库</view>
						</u-grid-item>
						
					</u-grid>
				</view>
			<!-- </view> -->
			


			<view v-if="value.includes('重庆胖子鱼') || value.includes('测试')">
				<!-- (重庆胖子鱼) -->
				<view class="workbench-title">基础应用(重庆胖子鱼)</view>
				<view class="toolbar">
					<u-grid class="grid" :col="4" :border="false">
						<u-grid-item @click="navTo('/pages/chongqing-pzy/out/index')">
							<view class="home-icon icon-color04">
								<i class="iconfont icon-a-ToBzhuangche3x"></i>
							</view>
							<view class="grid-text">下架执行</view>
						</u-grid-item>
						<u-grid-item  @click="navTo('/pages/chongqing-pzy/pd/index')">
							<view class="home-icon icon-color05">
								<i class="iconfont icon-PDA"></i>
							</view>
							<view class="grid-text">盘点执行</view>
						</u-grid-item>
						<!-- <u-grid-item  @click="navTo('/components/pda/touch/touch')">
							<view class="home-icon icon-color05">
								<i class="iconfont icon-PDA"></i>
							</view>
							<view class="grid-text">滑动测试</view>
						</u-grid-item> -->
					</u-grid>
				</view>
			</view>
			<view v-if="value.indexOf('川南') != -1 || value.includes('测试')">
				<view class="workbench-title">基础应用(川南)</view>
				<view class="toolbar">
					<u-grid class="grid" :col="4" :border="false">
						<u-grid-item @click="navTo('/pages/sys/inventory-location/index')">
							<view class="home-icon icon-color05">
								<i class="iconfont icon-a-chanpincaozuochaxun3x"></i>
							</view>
							<view class="grid-text">货位盘查</view>
						</u-grid-item>
						<u-grid-item :index="0" @click="navTo('/pages/chuan-nan/storage/index')">
							<view class="home-icon icon-color01">
								<i class="iconfont icon-a-shangjiadan3x"></i>
							</view>
							<view class="grid-text">收货入库</view>
						</u-grid-item>
						<u-grid-item :index="0" @click="navTo('/pages/chuan-nan/inventory-check/index')">
							<view class="home-icon icon-color04">
								<i class="iconfont icon-PDA"></i>
							</view>
							<view class="grid-text">盘点执行</view>
						</u-grid-item>
						<u-grid-item :index="0" @click="navTo('/pages/chuan-nan/conserve/index')">
							<view class="home-icon icon-color05">
								<i class="iconfont icon-template"></i>
							</view>
							<view class="grid-text">养护执行</view>
						</u-grid-item>
					</u-grid>
				</view>
			</view>



			<view v-show="value.indexOf('测试') != -1">
				<view class="workbench-title">常用应用</view>
				<view class="toolbar">
					<u-grid class="grid" :col="4" :border="false">
						<u-grid-item :index="0" @click="navTo('/pages/sys/storage/index')">
							<view class="home-icon icon-color01">
								<i class="iconfont icon-a-shangjiadan3x"></i>
							</view>
							<view class="grid-text">收货入库</view>
						</u-grid-item>
						<u-grid-item @click="navTo('/pages/sys/out/index')">
							<view class="home-icon icon-color04">
								<i class="iconfont icon-a-ToBzhuangche3x"></i>
							</view>
							<view class="grid-text">下架执行</view>
						</u-grid-item>
						<u-grid-item @click="navTo('/pages/sys/diaphragm/index')">
							<view class="home-icon icon-color04">
								<i class="iconfont icon-a-yiweidan3x"></i>
							</view>
							<view class="grid-text">隔膜出入库</view>
						</u-grid-item>
						<!-- <u-grid-item :index="1" @click="navTo('/pages/sys/outbound/index')">
						  			<view class="home-icon icon-color04">
						  				<i class="iconfont icon-hetongguanli"></i>
						  			</view>
						  			<view class="grid-text">出库下架</view>
						  		</u-grid-item> -->
						<u-grid-item :index="2" @click="navTo('/pages/sys/call-emput-tray/index')">
							<view class="home-icon icon-color03">
								<i class="iconfont icon-a-huoquanzhuanyi3x"></i>
							</view>
							<view class="grid-text">呼叫空托</view>
						</u-grid-item>
						<u-grid-item :index="2" @click="navTo('/pages/sys/in-emput-tray/index')">
							<view class="home-icon icon-color12">
								<i class="iconfont icon-a-datuo3x"></i>
							</view>
							<view class="grid-text">空托入库</view>
						</u-grid-item>
						<u-grid-item :index="2" @click="navTo('/pages/sys/stereoscopic/index')">
							<view class="home-icon icon-color05">
								<i class="iconfont icon-a-dingzhihuabaobiao3x"></i>
							</view>
							<view class="grid-text">托盘回库</view>
						</u-grid-item>

						<u-grid-item @click="navTo('/pages/sys/shelf-move/index')">
							<view class="home-icon icon-color03">
								<i class="iconfont icon-chengchangzhiyin"></i>
							</view>
							<view class="grid-text">货架移位</view>
						</u-grid-item>
						<u-grid-item @click="navTo('/pages/sys/replenishment/index')">
							<view class="home-icon icon-color04">
								<i class="iconfont icon-a-rukudan3x"></i>
							</view>
							<view class="grid-text">离线入库</view>
						</u-grid-item>
						<u-grid-item @click="navTo('/pages/sys/scrap-frame-handling/index')">
							<view class="home-icon icon-color04">
								<i class="iconfont icon-a-rukudan3x"></i>
							</view>
							<view class="grid-text">废料框搬运</view>
						</u-grid-item>
					</u-grid>
				</view>
				<view class="workbench-title">线边仓</view>
				<view class="toolbar">
					<u-grid class="grid" :col="4" :border="false">

						<u-grid-item :index="2" @click="navTo('/pages/sys/line-side-warehouse/index')">
							<view class="home-icon icon-color03">
								<i class="iconfont icon-yuetaiguanli"></i>
							</view>
							<view class="grid-text">线边仓作业</view>
						</u-grid-item>
						<u-grid-item :index="2" @click="navTo('/pages/sys/line-side-make/index')">
							<view class="home-icon icon-color12">
								<i class="iconfont icon-a-zengzhifuwu3x"></i>
							</view>
							<view class="grid-text">线边仓制单</view>
						</u-grid-item>
						<u-grid-item @click="navTo('/pages/sys/quality-release/index')">
							<view class="home-icon icon-color01">
								<i class="iconfont icon-a-caiwuguanli3x"></i>
							</view>
							<view class="grid-text">质量放行</view>
						</u-grid-item>
						<u-grid-item @click="navTo('/pages/sys/location-processing/index')">
							<view class="home-icon icon-color05">
								<i class="iconfont icon-yichang"></i>
							</view>
							<view class="grid-text">异常处理</view>
						</u-grid-item>

					</u-grid>
				</view>
				<view class="workbench-title">盘查</view>
				<view class="toolbar">
					<u-grid class="grid" :col="4" :border="false">
						<u-grid-item @click="navTo('/pages/sys/inventory-location/index')">
							<view class="home-icon icon-color05">
								<i class="iconfont icon-a-chanpincaozuochaxun3x"></i>
							</view>
							<view class="grid-text">货位盘查</view>
						</u-grid-item>
						<u-grid-item :index="0" @click="navTo('/pages/sys/inventory-check/index')">
							<view class="home-icon icon-color04">
								<!-- <i class="iconfont icon-a-kucunchaxun3x"></i> -->
								<i class="iconfont icon-PDA"></i>

							</view>
							<view class="grid-text">盘点执行</view>
						</u-grid-item>
						<u-grid-item @click="navTo('/pages/sys/reporting-losses/index')">
							<view class="home-icon icon-color04">
								<!-- <i class="iconfont icon-a-PDAyichangchuli3x"></i> -->
								<i class="iconfont icon-cry"></i>

							</view>
							<view class="grid-text">库存报损</view>
						</u-grid-item>
					</u-grid>
				</view>
				<view class="workbench-title">其他任务</view>
				<view class="toolbar">
					<u-grid class="grid" :col="4" :border="false">
						<!-- <u-grid-item :index="0" @click="navTo('')">
						  			<view class="home-icon icon-color04">
						  				<i class="iconfont icon-yongche"></i>
						  			</view>
						  			<view class="grid-text">用车</view>
						  		</u-grid-item> -->
						<u-grid-item :index="2" @click="navTo('/pages/sys/relocation/index')">
							<view class="home-icon icon-color03">
								<!-- <i class="iconfont icon-a-baojiadan3x"></i> -->
								<i class="iconfont icon-change"></i>

							</view>
							<view class="grid-text">移库</view>
						</u-grid-item>
						<u-grid-item :index="2" @click="navTo('/pages/sys/search-bucket/index')">
							<view class="home-icon icon-color12">
								<i class="iconfont icon-a-pingtaiguanli3x"></i>
							</view>
							<view class="grid-text">调货架</view>
						</u-grid-item>
						<u-grid-item :index="2" @click="navTo('/pages/sys/set-gzt/index')">
							<view class="home-icon icon-color01">
								<i class="iconfont icon-a-tiaozhengdan3x"></i>
							</view>
							<view class="grid-text">工作站绑定</view>
						</u-grid-item>

						<!-- <u-grid-item @click="navTo('')">
						  			<view class="home-icon icon-color04">
						  				<i class="iconfont icon-haocaifei"></i>
						  			</view>
						  			<view class="grid-text">耗材</view>
						  		</u-grid-item>
						  		<u-grid-item @click="navTo('')">
						  			<view class="home-icon icon-color01">
						  				<i class="iconfont icon-gongwujiedai"></i>
						  			</view>
						  			<view class="grid-text">接待</view>
						  		</u-grid-item>
						  		<u-grid-item @click="navTo('')">
						  			<view class="home-icon icon-color04">
						  				<i class="iconfont icon-baoming"></i>
						  			</view>
						  			<view class="grid-text">报名</view>
						  		</u-grid-item> -->
					</u-grid>
				</view>
			</view>
		</view>


		<!-- <view class="workbench-title">财务报销</view>
		<view class="toolbar"> -->
		<!-- <u-grid class="grid" :col="4" :border="false">
				<u-grid-item :index="0" @click="navTo('')">
					<view class="home-icon icon-color04">
						<i class="iconfont icon-finance"></i>
					</view>
					<view class="grid-text">费用报销</view>
				</u-grid-item>
				<u-grid-item :index="2" @click="navTo('')">
					<view class="home-icon icon-color03">
						<i class="iconfont icon-mall-bag"></i>
					</view>
					<view class="grid-text">采购申请</view>
				</u-grid-item>
				<u-grid-item :index="2" @click="navTo('')">
					<view class="home-icon icon-color12">
						<i class="iconfont icon-baoxiaodan"></i>
					</view>
					<view class="grid-text">付款申请</view>
				</u-grid-item>
				<u-grid-item @click="navTo('')">
					<view class="home-icon icon-color04">
						<i class="iconfont icon-shenpi"></i>
					</view>
					<view class="grid-text">用章申请</view>
				</u-grid-item>
			</u-grid>
		</view> -->
		<u-divider class="">已经到底了</u-divider>
		<u-divider v-show="baseUrl">{{baseUrl}}</u-divider>
	</view>

</template>
<script>
	import HeadNavBar from '@/components/headnavbar/index';
	// import monitorScanCode from "@/components/pda/pda-sacn/monitorScanCode.vue";
	import monitorScanCode from "@/components/pda/pda-sacn/scan-tool.vue";
	/**
	 * Copyright (c) 2013-Now http://aidex.vip All rights reserved.
	 */
	export default {
		components: {
			HeadNavBar,
			monitorScanCode
		},
		
		data() {
			return {
				baseUrl:'',
				errText: '请前往系统设置中进行注册',
				baseService: false,
				scanCodeIsShow: false,
				value: '',
				form: {
					a: '',
					b: ''
				},
				show: false,
				border: true,
				actionSheetList: [],
				pointList: [],
				title: 'picker',
				// array: ['中国', '美国', '巴西', '日本'],
				index: 0,
				// date: currentDate,
				time: '12:01',
				show: true,
				list: [{
						value: '1',
						label: '江'
					},
					{
						value: '2',
						label: '湖'
					}
				],
				show: false,
				head: '/static/aidex/images/head.png',
				imgList: [{
						image: '/static/aidex/banner/banner01.png'
					},
					{
						image: '/static/aidex/banner/banner02.png'
					},
					{
						image: '/static/aidex/banner/banner03.png'
					}
				],
				todoCount: 3
			};
		},
		created() {
			this.refreshScan()

		},
		onShow() {
			var _this = this
			uni.$off('scancodedate') // 每次进来先 移除全局自定义事件监听器
			uni.$on('scancodedate', function(data) {
				console.log('扫描,想要的code：', data.code)
			})
		},
		//下拉刷新触发方法(和onLoad同级)
		// onPullDownRefresh () {
		//     this.getBaseService()  //获取数据
		// 	setTimeout(function () {
		// 	            uni.stopPullDownRefresh();
		// 	        }, 300);
		// },
		onLoad() {
				
			this.actionSheetList = JSON.parse(uni.getStorageSync("storageList"))
			this.actionSheetList.push({
				"STORAGE_NAME": "测试全部菜单",
				"LIANXR": "ADMIN",
				"PHONE": "",
				"ADDRESS": "",
				"STORAGE_ID": "SC2",
				"text": "测试全部菜单"
			})
			if (this.actionSheetList.length > 0) {
				// this.errText = '暂未获取到用户ID为'+uni.getStorageSync("USER_ID")+'的工作台列表,请联系管理员'
				// return;
				// this.actionSheetList.push({
				// 	"STORAGE_NAME": "测试全部菜单",
				// 	"LIANXR": "ADMIN",
				// 	"PHONE": "",
				// 	"ADDRESS": "",
				// 	"STORAGE_ID": "SC2",
				// 	"text": "测试全部菜单"
				// })
				
				// if (process.env.NODE_ENV === 'development') {
				// 	this.actionSheetList.push({
				// 		"STORAGE_NAME": "测试全部菜单",
				// 		"LIANXR": "ADMIN",
				// 		"PHONE": "",
				// 		"ADDRESS": "",
				// 		"STORAGE_ID": "SC2",
				// 		"text": "测试全部菜单"
				// 	})
				// 	console.log('开发环境');
				// 	this.baseUrl = uni.getStorageSync("baseUrl")
				// } else {
				// 	console.log('生产环境');
				// }


				// this.huojListCenter = data.map(v => {
				//                                 this.$set(v, 'checked', true) // https://vuejs.org/v2/guide/reactivity.html
				//                                 this.$set(v, 'disabled', false)
				//                                 if(v.JOB_STATUS == '2'){
				//                                     this.$set(v, 'value', v.BUCKETCODE + v.WORKFACE)
				//                                     this.$set(v, 'name', v.BUCKETCODE + v.WORKFACE)
				//                                     return v
				//                                 }

				//                             })

			} else {
				// this.errText = '暂未获取到用户ID为' + uni.getStorageSync("USER_ID") + '的工作台列表,请联系管理员'
				// return;
			}
			console.log("主页从缓存中获取到的仓库下拉列表" + JSON.stringify(this.actionSheetList))
			// this.getStorage()
			// const value = uni.getStorageSync('warehouse')
			this.value = uni.getStorageSync('warehouse')
			// 如果没有选过值,并且如果有仓库列表,那么就获取第一个并缓存
			if (!this.value) {
				if (this.actionSheetList) {
					this.actionSheetCallback(0)
				}
			}
			this.getBaseService()
		},
		onTabItemTap: function(item) {
			console.log(item)
			uni.setStorageSync('connectionTest', false);

		},
		//下拉刷新触发方法(和onLoad同级)
		onPullDownRefresh() {
			this.getBaseService() //获取数据
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 300);
		},
		methods: {
			getBaseService() {
				this.baseService = uni.getStorageSync("baseService")
				// this.$u.toast(JSON.stringify(this.baseService ))
				//// 直接保存注册时间 2022-01-01/2031-01-01
				let registered_time = uni.getStorageSync('registered_time')
				let timeArr = registered_time.split("/");

				var date = new Date();
				//获取当前年份：
				var year = date.getFullYear();
				//获取当前月份：

				var month = date.getMonth() + 1;
				//获取当前日：

				var day = date.getDate();
				//获取当前日期（年-月-日）：

				month = (month > 9) ? month : ("0" + month);
				day = (day < 10) ? ("0" + day) : day;
				// 获取当前时间
				var today = year + "-" + month + "-" + day;
				// 当前时间这里,需要和服务器联动一下,防止用户自主修改设备时间,来跳过
				if (timeArr) {
					console.log(timeArr)
					if (timeArr[0]) {
						if (today > timeArr[0]) {
							console.log('当前日期在注册日之后');
							if (today < timeArr[1]) {
								console.log('当前日期在限定日之前');
								this.baseService = true
							}
						}
					} else {
						this.baseService = false
					}
				} else {
					this.baseService = false
				}

			},
			getNowDate() {


			},
			// 刷新扫描组件
			refreshScan() {
				this.scanCodeIsShow = false;
				this.$nextTick(() => {
					this.scanCodeIsShow = true;
				})
			},
			// 点击actionSheet回调
			actionSheetCallback(index) {
				// 表层文字
				this.value = this.actionSheetList[index].text;
				uni.setStorageSync('warehouse', this.value)

				// id
				const STORAGE_ID = this.actionSheetList[index].STORAGE_ID;
				uni.setStorageSync('STORAGE_ID', STORAGE_ID)
				console.log("缓存中的STORAGE_ID:" + uni.getStorageSync('STORAGE_ID'))
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
			},
			getStorage(loginType) {
				const user_id = uni.getStorageSync('USER_ID')
				let param = user_id;
				console.log(param)
				this.$u.api.general({
						iv_code: "USERSTORAGEROLE",
						iv_parm: param
					})
					.then(res => {
						console.log("返回的res:" + JSON.stringify(res))
						let data = res.data
						console.log("返回的data:" + JSON.stringify(data))
						if (res.success) {
							//补充text
							this.actionSheetList = data.map(v => {
								this.$set(v, 'text', v
									.STORAGE_NAME) // https://vuejs.org/v2/guide/reactivity.html
								return v
							})
						} else {
							this.$u.toast(res.msg);
						}
					});
			},
			// bindDateChange: function(e) {
			// 	this.date = e.detail.value
			// },
			// bindTimeChange: function(e) {
			// 	this.time = e.detail.value
			// },
			// getDate(type) {
			// 	const date = new Date();
			// 	let year = date.getFullYear();
			// 	let month = date.getMonth() + 1;
			// 	let day = date.getDate();

			// 	if (type === 'start') {
			// 		year = year - 60;
			// 	} else if (type === 'end') {
			// 		year = year + 2;
			// 	}
			// 	month = month > 9 ? month : '0' + month;
			// 	day = day > 9 ? day : '0' + day;
			// 	return `${year}-${month}-${day}`;
			// },
			// 注意返回值为一个数组，单列时取数组的第一个元素即可(只有一个元素)
			confirm(e) {
				console.log(e);
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				});
			},
			imgListClick(index) {
				console.log(`点击了第${index + 1}页图片`)
			},
			itemClick(index) {
				console.log(index);
			}
		}
	};
</script>
<style lang="scss">
	@import 'index.scss';

	.banner-box {
		padding: 0 2%;
		width: 96%;
		height: 170rpx;
		margin: 30rpx 0 30rpx;
	}

	.u-swiper-wrap {
		padding: 0 10px;
	}

	.banner-pic {
		width: 47%;
		float: left;
		display: inline-block;
		margin: 0 1.5%;
	}

	.banner-pic image {
		width: 100%;
		height: 170rpx;
		border-radius: 12rpx;
		box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
	}

	.u-mode-light-info {
		background-color: #ffffff;
		color: #666666;
		border: 1px solid #e9ecf6;
		font-size: 12px;
		padding: 2px 8px;
		position: relative;
		top: -3px;
	}

	.workbench-title {
		font-size: 32rpx;
		font-weight: bold;
		color: #333333;
		padding: 15px 30rpx;
	}

	.home-icon i.icon-tongzhi {
		font-size: 22px;
	}
</style>